package com.zmn.oms.third.yunding;

import com.zmn.oms.common.constant.OrderConsts;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 云丁鹿客渠道常量定义类
 *
 * @author xiewenbing
 * @date 2020/09/08
 */
@Component
public class YundingConsts {

    /**
     * 渠道名称
     */
    public final static String CHANNEL_NAME = "天津云丁网络信息服务有限公司";

    /**
     * 渠道对接开关
     */
    public static boolean POWER_ON = true;

    /**
     * 厂商id
     */
    public static int FACTORY_ID = 50646;

    /**
     * Redis 缓存时间
     */
    public final static int REDIS_CACHE_TIMEOUT = (3600 * 24 * 30);

    /**
     * APP KEY
     */
    public static String APP_KEY = "127655DDB2F39F91F935577C0A2D4200";

    /**
     * APP SECRET
     */
    public static String APP_SECRET = "908F8C64E2CF08FDA9F799F9FC84BB7E";

    /**
     * API URL
     */
    public static String API_URL = "http://dev-boss-server.dding.net:7001/";

    /**
     * 云丁-智能锁安装 产品ID
     */
    public final static int PRODUCT_ID_INSTALL = 11805;

    /**
     * 云丁-智能锁维修 产品ID
     */
    public final static int PRODUCT_ID_REPAIR = 11806;

    /**
     * 师傅空跑金额
     */
    public final static int MASTER_ONLYRUN_AMOUNT = 3000;

    /**
     * 云丁鹿客渠道师傅电话
     */
    public final static String MASTER_PHONE = "13350300176";

    /**
     * 师傅缺省填入
     */
    public final static String MASTER_DEFAULT_NAME = "啄木鸟师傅";

    /**
     * 师傅空跑原因
     */
    public final static String MASTER_ONLYRUN_REASON = "用户不想安装/维修了";

    /**
     * 云丁维修工单替换类型
     */
    public final static String ORDER_REPAIR_RELACE_TYPE = "商品";

    /**
     * 同步订单状态请求PATH
     */
    public final static String SYNC_ORDER_STATUS_PATH = "openapi/v1/woodpecker/operation";

    /**
     * 旧件回寄请求PATH
     */
    public final static String OLD_PART_SENDBACK_PATH = "openapi/v1/woodpecker/sendBack";

    /**
     * 状态同步 - type
     */
    public final static String TYPE_ORDER_STATUS = "ORDER_STATUS";

    /**
     * 云丁鹿客订单状态-待安排师傅
     */
    public final static String ORDER_STATUS_WAITING_GRAB = "WAITING_GRAB";

    /**
     * 云丁鹿客订单状态-待师傅联系
     */
    public final static String ORDER_STATUS_WAITING_COMMUNICATE = "WAITING_COMMUNICATE";

    /**
     * 云丁鹿客订单状态-待师傅上门
     */
    public final static String ORDER_STATUS_WAITING_SERVE = "WAITING_SERVE";

    /**
     * 云丁鹿客订单状态-待施工
     */
    public final static String ORDER_STATUS_WAITING_CONSTRUCT = "WAITING_CONSTRUCT";

    /**
     * 云丁鹿客订单状态-上门未安装
     */
    public final static String ORDER_STATUS_SERVED_NOT_INSTALL = "SERVED_NOT_INSTALL";

    /**
     * 云丁鹿客订单状态-完成
     */
    public final static String ORDER_STATUS_COMPLETED = "COMPLETED";

    /**
     * 云丁鹿客订单状态-取消
     */
    public final static String ORDER_STATUS_CANCELED = "CANCELED";

    /**
     * 服务类型code - 安装
     */
    public final static String SERVICE_TYPE_CODE_INSTALLATION = "INSTALLATION";

    /**
     * 服务类型code - 维修：换锁
     */
    public final static String SERVICE_TYPE_CODE_REPLACE_LOCK = "REPLACE_LOCK";

    /**
     * 服务类型code - 维修：其他
     */
    public final static String SERVICE_TYPE_CODE_MAINTAINING = "MAINTAINING";

    /**
     * 成功 code返回值
     */
    public final static String RESPONSE_CODE_SUCCESS = "100000";

    /**
     * 成功 message返回值
     */
    public final static String RESPONSE_MESSAGE_SUCCESS = "成功";

    /**
     * 系统错误 code返回值
     */
    public final static String RESPONSE_CODE_SYSTEM_ERROR = "100001";

    /**
     * app_key 不存在 code返回值
     */
    public final static String RESPONSE_CODE_APPKEY_NO_EXIST = "200000";

    /**
     * 暂不支持该服务 code返回值
     */
    public final static String RESPONSE_CODE_UNSUPPORT_SERVICE = "200100";

    /**
     * 参数校验失败 code返回值
     */
    public final static String RESPONSE_CODE_PARAM_ERROR = "200001";

    /**
     * 商品id错误 code返回值
     */
    public final static String RESPONSE_CODE_GOODS_ID_ERROR = "200101";

    /**
     * 商户余额不足 code返回值
     */
    public final static String RESPONSE_CODE_BALANCE_NO_ENOUGH = "200002";

    /**
     * 商户不存在 code返回值
     */
    public final static String RESPONSE_CODE_MERCHANTS_NO_EXIST = "200003";

    /**
     * 取消成功 code返回值
     */
    public final static String RESPONSE_CODE_CANCEL_SUCCESS = "200004";

    /**
     * 需要通知服务商客服人工取消 code返回值
     */
    public final static String RESPONSE_CODE_NEED_MANUAL_CANCEL = "200005";

    /**
     * 该工单不存在 code返回值
     */
    public final static String RESPONSE_CODE_ORDER_NO_EXIST = "200006";

    /**
     * 当前客户地区还未培养出师傅，暂不提供服务 - code返回值
     */
    public final static String RESPONSE_CODE_AREA_UNSUPPORT = "200007";

    /**
     * 必要参数缺失或错误 code返回值
     */
    public final static String RESPONSE_CODE_PARAM_MISS = "200009";

    /**
     * 工单商品缺少对应服务类别 - code返回值
     */
    public final static String RESPONSE_CODE_SERVICE_NO_EXIST = "200010";


    /**
     * 解决方案-产品升级
     */
    public final static String PROCESS_METHOD_PRODUCT_UPGRADES = "PRODUCT_UPGRADES";

    /**
     * 解决方案-上门调试
     */
    public final static String PROCESS_METHOD_VISIT_DEBUG = "VISIT_DEBUG";

    /**
     * 解决方案-更换整锁
     */
    public final static String PROCESS_METHOD_REPLACE_WHOLE_LOCK = "REPLACE_WHOLE_LOCK";

    /**
     * 解决方案-更换面板
     */
    public final static String PROCESS_METHOD_REPLACE_FACEPLATE = "REPLACE_FACEPLATE";

    /**
     * 解决方案-更换锁体
     */
    public final static String PROCESS_METHOD_REPLACE_LOCK_BODY = "REPLACE_LOCK_BODY";

    /**
     * 解决方案-更换侧条
     */
    public final static String PROCESS_METHOD_REPLACE_SIDE_BAR = "REPLACE_SIDE_BAR";

    /**
     * 解决方案-更换锁芯
     */
    public final static String PROCESS_METHOD_REPLACE_LOCK_CORE = "REPLACE_LOCK_CORE";

    /**
     * 解决方案-更换指纹头
     */
    public final static String PROCESS_METHOD_REPLACE_FINGERPRINT_HEAD = "REPLACE_FINGERPRINT_HEAD";

    /**
     * 解决方案-更换网关
     */
    public final static String PROCESS_METHOD_REPLACE_GATEWAY = "REPLACE_GATEWAY";

    /**
     * 根据错误码获取提示消息
     * @param code
     * @return
     */
    public static String getErrMsgByCode(String code) {

        switch (code) {
            case RESPONSE_CODE_SUCCESS:
                return "成功";
            case RESPONSE_CODE_SYSTEM_ERROR:
                return "系统错误 ";
            case RESPONSE_CODE_APPKEY_NO_EXIST:
                return "app_key 不存在";
            case RESPONSE_CODE_AREA_UNSUPPORT:
                return "前客户地区还未培养出师傅，暂不提供服务";
            case RESPONSE_CODE_BALANCE_NO_ENOUGH:
                return "商户余额不足";
            case RESPONSE_CODE_CANCEL_SUCCESS:
                return "取消成功";
            case RESPONSE_CODE_GOODS_ID_ERROR:
                return "商品id错误";
            case RESPONSE_CODE_MERCHANTS_NO_EXIST:
                return "商户不存在";
            case RESPONSE_CODE_NEED_MANUAL_CANCEL:
                return "需要通知服务商客服人工取消";
            case RESPONSE_CODE_ORDER_NO_EXIST:
                return "该工单不存在";
            case RESPONSE_CODE_PARAM_ERROR:
                return "参数校验失败";
            case RESPONSE_CODE_PARAM_MISS:
                return "必要参数缺失或错误";
            case RESPONSE_CODE_SERVICE_NO_EXIST:
                return "工单商品缺少对应服务类别";
            case RESPONSE_CODE_UNSUPPORT_SERVICE:
                return "暂不支持该服务";
        }

        return "Unknown Error";
    }

    public static String getStatusName(String status) {

        switch (status) {
            case ORDER_STATUS_WAITING_GRAB:
                return "待安排师傅";
            case ORDER_STATUS_WAITING_COMMUNICATE:
                return "待师傅联系";
            case ORDER_STATUS_WAITING_SERVE:
                return "待师傅上门";
            case ORDER_STATUS_WAITING_CONSTRUCT:
                return "待施工";
            case ORDER_STATUS_SERVED_NOT_INSTALL:
                return "上门未安装";
            case ORDER_STATUS_COMPLETED:
                return "完成";
            case ORDER_STATUS_CANCELED:
                return "取消";
        }

        return "Unknown status";
    }

    /**
     * 通过显示索引来获取解决方案
     * @param index
     * @return
     */
    public static String getProcessMethodByIndex(int index) {

        switch (index) {
            case 0:
                return PROCESS_METHOD_PRODUCT_UPGRADES;
            case 1:
                return PROCESS_METHOD_VISIT_DEBUG;
            case 2:
                return PROCESS_METHOD_REPLACE_WHOLE_LOCK;
            case 3:
                return PROCESS_METHOD_REPLACE_FACEPLATE;
            case 4:
                return PROCESS_METHOD_REPLACE_LOCK_BODY;
            case 5:
                return PROCESS_METHOD_REPLACE_SIDE_BAR;
            case 6:
                return PROCESS_METHOD_REPLACE_LOCK_CORE;
            case 7:
                return PROCESS_METHOD_REPLACE_FINGERPRINT_HEAD;
            case 8:
                return PROCESS_METHOD_REPLACE_GATEWAY;
        }

        return PROCESS_METHOD_PRODUCT_UPGRADES;
    }

    /**
     * 获取解决方案的索引
     * @param method
     * @return
     */
    public static int getProcessMethodIndex(String method) {

        switch (method) {
            case PROCESS_METHOD_PRODUCT_UPGRADES:
                return 0;
            case PROCESS_METHOD_VISIT_DEBUG:
                return 1;
            case PROCESS_METHOD_REPLACE_WHOLE_LOCK:
                return 2;
            case PROCESS_METHOD_REPLACE_FACEPLATE:
                return 3;
            case PROCESS_METHOD_REPLACE_LOCK_BODY:
                return 4;
            case PROCESS_METHOD_REPLACE_SIDE_BAR:
                return 5;
            case PROCESS_METHOD_REPLACE_LOCK_CORE:
                return 6;
            case PROCESS_METHOD_REPLACE_FINGERPRINT_HEAD:
                return 7;
            case PROCESS_METHOD_REPLACE_GATEWAY:
                return 8;
        }

        return 1;
    }

    /**
     * 获取解决方案的名称
     * @param method
     * @return
     */
    public static String getProcessMethodName(String method) {

        switch (method) {
            case PROCESS_METHOD_PRODUCT_UPGRADES:
                return "产品升级";
            case PROCESS_METHOD_VISIT_DEBUG:
                return "上门调试";
            case PROCESS_METHOD_REPLACE_WHOLE_LOCK:
                return "更换整锁";
            case PROCESS_METHOD_REPLACE_FACEPLATE:
                return "更换面板";
            case PROCESS_METHOD_REPLACE_LOCK_BODY:
                return "更换锁体";
            case PROCESS_METHOD_REPLACE_SIDE_BAR:
                return "更换侧条";
            case PROCESS_METHOD_REPLACE_LOCK_CORE:
                return "更换锁芯";
            case PROCESS_METHOD_REPLACE_FINGERPRINT_HEAD:
                return "更换指纹头";
            case PROCESS_METHOD_REPLACE_GATEWAY:
                return "更换网关";
        }

        return "";
    }

    /**
     * 通过服务类型获取产品id（后台）
     * @param code
     * @return
     */
    public static Integer getProductIdByServiceCode(String code) {

        switch (code) {
            case SERVICE_TYPE_CODE_INSTALLATION:
                return PRODUCT_ID_INSTALL;
            case SERVICE_TYPE_CODE_REPLACE_LOCK:
            case SERVICE_TYPE_CODE_MAINTAINING:
                return PRODUCT_ID_REPAIR;
        }

        return OrderConsts.CHANNEL_DISABLED_PRODUCT_ID;
    }

    @Value("${yunding.api.powerOn:false}")
    public void setPowerOn(boolean powerOn) {
        POWER_ON = powerOn;
    }

    @Value("${yunding.api.url:http://dev-boss-server.dding.net:7001/}")
    public void setApiUrl(String apiUrl) {
        API_URL = apiUrl;
    }

    @Value("${yunding.app.secret:908F8C64E2CF08FDA9F799F9FC84BB7E}")
    public void setAppSecret(String appSecret) {
        APP_SECRET = appSecret;
    }

    @Value("${yunding.app.key:127655DDB2F39F91F935577C0A2D4200}")
    public void setAppKey(String appKey) {
        APP_KEY = appKey;
    }
}
